package com.ejia.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.ejia.pojo.car;
import com.ejia.pojo.house;
import com.ejia.pojo.user;
import com.ejia.server.CarServices;
import com.ejia.server.HouseService;
import com.ejia.server.UserService;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import java.awt.Font;
import java.awt.TextField;
import java.util.ArrayList;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import java.awt.SystemColor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Toolkit;

public class UserInfo extends JFrame {

	private JPanel contentPane;
	private JLabel label;
	private JTextField textField;
	private JLabel label_1;
	private JTextField textField_1;
	private JLabel label_2;
	private JTextField textField_2;
	private JLabel label_3;
	private JTextField textField_3;
	private JLabel label_4;
	private JTextField textField_4;
	private JLabel label_5;
	private JTextField textField_5;
	private JLabel label_6;
	private JTextField textField_6;
	private JLabel label_7;
	private JTextField textField_7;
	private JLabel label_8;
	private JTextField textField_8;
	private JLabel label_9;
	private JTextField textField_9;
	private JLabel label_10;
	private JButton button;
	private static ArrayList<car> cars;
	private static int j=0;
	private JLabel label_11;
	private JTextField textField_10;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UserInfo frame = new UserInfo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	

	/**
	 * Create the frame.
	 */
	public UserInfo() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(UserInfo.class.getResource("/com/ejia/photo/客户管理系统.png")));
		setTitle("用户信息");
		
		
		ArrayList<user> users= new ArrayList<>();
		users= UserService.findRealname(login.cname);
		String name=users.get(0).getRealname();
		cars= CarServices.findinfo(name);
		
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 650);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(41, 108, 783, 377);
		contentPane.add(panel);
		panel.setLayout(null);
		
		label = new JLabel("姓名");
		label.setFont(new Font("宋体", Font.PLAIN, 28));
		label.setBounds(46, 22, 81, 36);
		panel.add(label);
		
		textField = new JTextField();
		textField.setFont(new Font("宋体", Font.PLAIN, 24));
		textField.setColumns(10);
		textField.setBounds(164, 21, 192, 39);
		panel.add(textField);
		
		label_1 = new JLabel("账号");
		label_1.setFont(new Font("宋体", Font.PLAIN, 28));
		label_1.setBounds(46, 80, 81, 35);
		panel.add(label_1);
		
		textField_1 = new JTextField();
		textField_1.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_1.setColumns(10);
		textField_1.setBounds(164, 78, 192, 38);
		panel.add(textField_1);
		
		label_2 = new JLabel("手机");
		label_2.setFont(new Font("宋体", Font.PLAIN, 28));
		label_2.setBounds(46, 137, 81, 39);
		panel.add(label_2);
		
		textField_2 = new JTextField();
		textField_2.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_2.setColumns(10);
		textField_2.setBounds(164, 135, 192, 42);
		panel.add(textField_2);
		
		label_3 = new JLabel("生日");
		label_3.setFont(new Font("宋体", Font.PLAIN, 28));
		label_3.setBounds(46, 198, 81, 35);
		panel.add(label_3);
		
		textField_3 = new JTextField();
		textField_3.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_3.setColumns(10);
		textField_3.setBounds(164, 196, 192, 38);
		panel.add(textField_3);
		
		label_4 = new JLabel("房号");
		label_4.setFont(new Font("宋体", Font.PLAIN, 28));
		label_4.setBounds(46, 255, 81, 36);
		panel.add(label_4);
		
		textField_4 = new JTextField();
		textField_4.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_4.setColumns(10);
		textField_4.setBounds(164, 254, 192, 39);
		panel.add(textField_4);
		
		label_5 = new JLabel("性别");
		label_5.setFont(new Font("宋体", Font.PLAIN, 28));
		label_5.setBounds(441, 21, 81, 39);
		panel.add(label_5);
		
		textField_5 = new JTextField();
		textField_5.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_5.setColumns(10);
		textField_5.setBounds(559, 19, 192, 42);
		panel.add(textField_5);
		
		label_6 = new JLabel("密码");
		label_6.setFont(new Font("宋体", Font.PLAIN, 28));
		label_6.setBounds(441, 78, 81, 38);
		panel.add(label_6);
		
		textField_6 = new JTextField();
		textField_6.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_6.setColumns(10);
		textField_6.setBounds(559, 77, 192, 41);
		panel.add(textField_6);
		
		label_7 = new JLabel("邮箱");
		label_7.setFont(new Font("宋体", Font.PLAIN, 28));
		label_7.setBounds(441, 137, 81, 39);
		panel.add(label_7);
		
		textField_7 = new JTextField();
		textField_7.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_7.setColumns(10);
		textField_7.setBounds(559, 135, 192, 42);
		panel.add(textField_7);
		
		label_8 = new JLabel("车位");
		label_8.setFont(new Font("宋体", Font.PLAIN, 28));
		label_8.setBounds(441, 196, 81, 38);
		panel.add(label_8);
		
		textField_8 = new JTextField();
		textField_8.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_8.setColumns(10);
		textField_8.setBounds(559, 195, 192, 41);
		panel.add(textField_8);
		
		label_11 = new JLabel("地址");
		label_11.setFont(new Font("宋体", Font.PLAIN, 28));
		label_11.setBounds(46, 313, 81, 36);
		panel.add(label_11);
		
		textField_10 = new JTextField();
		textField_10.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_10.setBounds(164, 312, 587, 39);
		panel.add(textField_10);
		textField_10.setColumns(10);
		
		label_9 = new JLabel("状态");
		label_9.setFont(new Font("宋体", Font.PLAIN, 28));
		label_9.setBounds(441, 254, 81, 39);
		panel.add(label_9);
		
		textField_9 = new JTextField();
		textField_9.setFont(new Font("宋体", Font.PLAIN, 24));
		textField_9.setColumns(10);
		textField_9.setBounds(559, 252, 192, 42);
		panel.add(textField_9);
		
		label_10 = new JLabel("小区名称：");
		label_10.setFont(new Font("宋体", Font.PLAIN, 36));
		label_10.setBounds(41, 24, 783, 60);
		contentPane.add(label_10);
		
		button = new JButton("修改");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int id=cars.get(0).getUserid().getId();
				if (CarServices.update1(textField_8.getText(), id) && UserService.update1(textField_1.getText(), textField_6.getText(), textField.getText(), textField_5.getText(), textField_2.getText(), Integer.parseInt(textField_4.getText()), textField_3.getText(),textField_7.getText(), textField_9.getText(), id) && HouseService.updateinfo(textField_10.getText(), textField_4.getText())) {
					JOptionPane.showMessageDialog(null, "修改成功");
					cars=CarServices.findinfo(name);
					textField.setText(cars.get(j).getUserid().getRealname());
					textField_5.setText(cars.get(j).getUserid().getSex());
					textField_1.setText(cars.get(j).getUserid().getUid());
					textField_6.setText(cars.get(j).getUserid().getPwd());
					textField_2.setText(cars.get(j).getUserid().getPhone());
					textField_7.setText(cars.get(j).getUserid().getEmail());
					textField_3.setText(cars.get(j).getUserid().getBirthday());
					textField_8.setText(cars.get(j).getCarnumber());
					textField_4.setText(""+cars.get(j).getUserid().getHid().getHid());
					textField_9.setText(cars.get(j).getUserid().getHid().getRemark());
					textField_10.setText(cars.get(j).getUserid().getHid().getAddress());
				}else {
					JOptionPane.showMessageDialog(null, "修改失败");
				}
			}
		});
		button.setFont(new Font("宋体", Font.PLAIN, 42));
		button.setBounds(624, 509, 200, 60);
		contentPane.add(button);
		
		
		
		textField.setText(cars.get(j).getUserid().getRealname());
		textField_5.setText(cars.get(j).getUserid().getSex());
		textField_1.setText(cars.get(j).getUserid().getUid());
		textField_6.setText(cars.get(j).getUserid().getPwd());
		textField_2.setText(cars.get(j).getUserid().getPhone());
		textField_7.setText(cars.get(j).getUserid().getEmail());
		textField_3.setText(cars.get(j).getUserid().getBirthday());
		textField_8.setText(cars.get(j).getCarnumber());
		textField_4.setText(""+cars.get(j).getUserid().getHid().getHid());
		textField_9.setText(cars.get(j).getUserid().getHid().getRemark());
		textField_10.setText(cars.get(j).getUserid().getHid().getAddress());
		
		JButton button_fh = new JButton("返回");
		button_fh.setFont(new Font("宋体", Font.PLAIN, 42));
		button_fh.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				new Mainuser().setVisible(true);
				dispose();
			}
		});
		button_fh.setBackground(SystemColor.controlHighlight);
		button_fh.setBounds(41, 509, 181, 60);
		contentPane.add(button_fh);
		

		setLocationRelativeTo(null);
	}
}
